package de.rubaff.reqiengi.database;

import java.util.List;

import com.db4o.Db4o;
import com.db4o.Db4oEmbedded;
import com.db4o.ObjectContainer;
import com.db4o.ObjectSet;
import com.google.inject.Inject;

import de.rubaff.reqiengi.objects.IId;
import de.rubaff.reqiengi.objects.Project;
import de.rubaff.reqiengi.objects.User;

public class DatabaseManager implements IDatabaseManager
{
	private ObjectContainer db;
	public static final String DB = "reqiengi";
	
	@Inject
	public DatabaseManager()
	{
		
	}
	
	@Override
	public void delete(IId obj)
	{
		this.db.delete(obj);		
	}

	@Override
	public List<Project> getAllProjects()
	{
		List result = db.query(Project.class);
		return result;
	}

	@Override
	public List<User> getAllUsers()
	{
		ObjectSet result = db.queryByExample(User.class);
		return result;
	}

	@Override
	public void store(IId obj)
	{
		this.db.store(obj);	
	}

	@Override
	public void closeDatabase()
	{
		this.db.close();		
	}

	@Override
	public void openDatabase(String name)
	{
		
		db = Db4oEmbedded.openFile(Db4oEmbedded.newConfiguration(), name);	
		
	}

	@Override
	public List<IId> getAllByClass(IId id)
	{
		ObjectSet result = db.queryByExample(id);
		return result;
	}

}
